package com.wutuo.roster.provider.component;

import cn.apestar.base.SpringContextHolder;
import cn.apestar.core.utils.TranslateUtil;
import cn.apestar.user.provider.institution.service.InstitutionService;
import com.wutuo.child.provider.service.ChildService;
import com.wutuo.roster.api.response.RosterResponse;
import com.wutuo.roster.provider.enums.EnumList;
import com.wutuo.roster.provider.service.ParentsService;
import com.wutuo.tag.provider.service.TagService;
import com.wutuo.wtservice.provider.service.UserServiceService;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Singer_YDW on 2016/11/10.
 */
public class RosterUtil {

    private static TagService tagService = SpringContextHolder.getBean(TagService.class);

    private static ParentsService parentsService =
        SpringContextHolder.getBean(ParentsService.class);

    private static UserServiceService userServiceService =
        SpringContextHolder.getBean(UserServiceService.class);

    private static InstitutionService institutionService = SpringContextHolder.getBean("institutionService");

    private static ChildService childService = SpringContextHolder.getBean(ChildService.class);

    // 翻译
    public static <T> void convertToCustomerResponseList(List<T> list) {

        TranslateUtil.translatEnumList(list, "tgZt", "tgZtName", EnumList.getTgEnumList());
        tagService.getTagByTagIds(list, "tagIds", "tag");
        parentsService.getPareantByParentsId(list, "parentIds", "parent");
        userServiceService.getUseServiceByRoasterId(list, "serviceIds", "tgTypeList");
        institutionService.getCminstanById(list, "cmInstitutionId", "institutionResponse", false);
    }

    // 翻译
    public static <T> void convertToChildResponseList(List<T> list) {

        TranslateUtil.translatEnumList(list, "tgZt", "tgZtName", EnumList.getTgEnumList());
        institutionService.getCminstanById(list, "cmInstitutionId", "institutionResponse", true);
        childService.getTaskDetailByChildId(list, "id", "callTask");
    }

    // 翻译
    public static void convertToChildNoTaskResponseList(List list) {

        TranslateUtil.translatEnumList(list, "tgZt", "tgZtName", EnumList.getTgEnumList());
        institutionService.getCminstanById(list, "cmInstitutionId", "institutionResponse", true);
    }

    // 翻译
    public static RosterResponse convertToCustomerResponse(RosterResponse s) {

        List<RosterResponse> list = new ArrayList<>();
        list.add(s);
        TranslateUtil.translatEnumList(list, "tgZt", "tgZtName", EnumList.getTgEnumList());
        tagService.getTagByTagIds(list, "tagIds", "tag");
        parentsService.getPareantByParentsId(list, "parentIds", "parent");
        userServiceService.getUseServiceByRoasterId(list, "serviceIds", "tgTypeList");
        institutionService.getCminstanById(list, "cmInstitutionId", "institutionResponse", false);
        return list.get(0);
    }

    // 翻译朋友圈数据
    public static RosterResponse convertToEliteResponse(RosterResponse s) {

        List<RosterResponse> list = new ArrayList<>();
        list.add(s);
        TranslateUtil.translatEnumList(list, "tgZt", "tgZtName", EnumList.getTgEnumList());
        tagService.getTagByTagIds(list, "tagIds", "tag");
        parentsService.getPareantByParentsId(list, "parentIds", "parent");
        userServiceService.getUseServiceByRoasterId(list, "serviceIds", "tgTypeList");
        institutionService.getCminstanById(list, "cmInstitutionId", "institutionResponse", false);
        return list.get(0);
    }
}
